
class Dialog:
    # dialog is a way of paging through long text
    def __init__(self, pages, game_state):
        self.pages = pages
        self.game_state = game_state
        self.page_index = 0
        self.max_page = len(pages)

    def current_page(self):
        return self.pages[self.page_index]

    def select(self):
        if self.page_index < self.max_page - 1:
            self.page_index += 1
        else:
            self.game_state.dialog_list.remove(self)

    def cancel(self):
        if self.page_index > 0:
            self.page_index -= 1

def new_how_to_play_dialog(game_state):
    t = '''A cryptogram is a word puzzle where each letter in a quote is replaced
by a different letter. Solve it by guessing letters, using letter
frequency and patterns, to reveal the original quote.'''
    return Dialog([t], game_state)

def new_about_dialog(game_state):
    t = '''PyCryptogram is developed by Jason K. MacDuffie and is designed to help
users solve and create cryptogram puzzles. It is released under the GNU
General Public License (GPLv3+), allowing users to freely use, modify,
and distribute the software. Any modifications or redistributed versions
must include this same license. For full terms and conditions, please
refer to the LICENSE file.'''
    return Dialog([t], game_state)

def new_game_over_dialog(game_state):
    quote_data = game_state.puzzle.quote
    if 'source' in quote_data:
        return Dialog([quote_data['quote'], quote_data['source']], game_state)
    else:
        return Dialog([quote_data['quote']], game_state)
